//
//  GQHCommentModel.m
//  Xanthium
//
//  Created by GuanQinghao on 09/04/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHCommentModel.h"


@implementation GQHCommentModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"qh_commentID" : @"id",
             @"qh_orderID" : @"waybillId",
             @"qh_score" : @"score",
             @"qh_commentContent" : @"evaluation",
             @"qh_commentTime" : @"evaluationTime",
             @"qh_commentatorID" : @"evaluationPeople",
             @"qh_reviewerID" : @"byEvaluation",
             
             @"qh_name" : @"userName",
             @"qh_type" : @"userType",
             @"qh_avatar" : @"headImg",
             @"qh_count" : @"evaCount"
             };
}

/// 获取评价 (评价我的和我评价的)
+ (void)qh_fetchCommentsWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHCommentModel *> *comments))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buAssessment/1/findAll"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *commentArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHCommentModel *commentModel = [GQHCommentModel yy_modelWithDictionary:object];
                if (commentModel) {
                    
                    [commentArray addObject:commentModel];
                }
            }
            success(YES,code,message,commentArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

@end
